package com.test.designPattern.creationType.prototypePattern;



import java.util.Hashtable;

/**
 * todo
 *
 * @author wangjie
 * @version V1.0
 * @date 2020/4/4
 */
public class ShapeCache {

    private static Hashtable<String, Shape> shapeMap = new Hashtable<String, Shape>();


    /**
     * 原型库
     */
    public  ShapeCache() {
        Circle circle = new Circle();
        circle.setId("1");
        shapeMap.put(circle.getId(),circle);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("2");
        shapeMap.put(rectangle.getId(),rectangle);
    }

    public Shape getShape(String shapeId) {
        Shape cachedShape = shapeMap.get(shapeId);
        return (Shape) cachedShape.clone();
    }
}
